public class SinglyLinkedList {
    private Node head;//初始化节点

    private static class Node{
        int value;//值
        Node next;//节点
        public Node(int value,Node next){//要加入的值 第几个节点
            this.value=value;
            this.next=next;
        }
    }
    //加入元素
    public void addFirst(Node node){
        Node tmp=head;
        //1.链表为空
       //  head = new Node(val,null);
        //2.链表非空
        new Node(node.value, head);//新创建节点，该节点指向原来的节点
    }
    //遍历链表
    public void loop(){
        Node p=head;
        while(p!=null){
            System.out.println(p.value);
            p=p.next;
        }
    }

    public static void main(String[] args) {
        SinglyLinkedList list=new SinglyLinkedList();
        list.addFirst(1);
        list.addFirst(2);
        list.addFirst(3);
        list.addFirst(4);
        list.loop();
    }
}
